
********************************************************************************
***   First stage 
********************************************************************************

est clear

foreach var of varlist school4 indiv2 indiv3 indiv4 {
	
	display " "
	display " "
	display " "
	display "Table A10a: `var' (main effect)"
	
	quietly: ivreg2 economic_index (`var' = instrument) i.locale_gender $controls if birthyear_control >= 1970 & birthyear_control <= 1997, cluster(locale_3_control) partial(i.birthyear_control i.year_survey_control i.locale_gender) savefirst savefprefix(post1)
	
	quietly: generate sample = e(sample)
	local fstat_`var' =round(e(widstat), 0.001)
	display "f-stat: `fstat_`var''"

	quietly eststo: areg `var' instrument i.birthyear_control i.year_survey_control post1 treat2_10_inc wolof-others if birthyear_control >= 1970 & birthyear_control <= 1997 & sample == 1, absorb(locale_gender) cluster(locale_3_control)
	
	noisily: lincom instrument 
	quietly: summ `var' if e(sample)
	estadd scalar vmean = r(mean)
	
	drop sample
	
	
	display " "
	display " "
	display " "
	display "Table A10b: `var' (democracy threatened)"
	
	quietly: ivreg2 economic_index (`var' c.`var'#c.W = instrument c.instrument#c.W) i.birthyear_control##c.W i.locale_gender##c.W c.post1##c.W c.treat2_10_inc##c.W $controls2 if birthyear_control >= 1970 & birthyear_control <= 1997, cluster(locale_3_control) partial(i.birthyear_control##c.W i.locale_gender##c.W c.post1##c.W c.treat2_10_inc##c.W) savefirst savefprefix(post1)
	
	quietly: generate sample = e(sample)
	
	local fstat2_`var' =round(e(widstat), 0.001)
	display "f-stat: `fstat2_`var''"
	
	quietly eststo: reg `var' instrument c.instrument#c.W i.birthyear_control##c.W i.locale_gender##c.W c.post1##c.W c.treat2_10_inc##c.W $controls2 if birthyear_control >= 1970 & birthyear_control <= 1997, cluster(locale_3_control)
			
	noisily: lincom instrument 
	noisily: lincom c.instrument#c.W
	
	quietly: summ `var' if e(sample)
	estadd scalar vmean = r(mean)
	
	drop sample
	
}

local gap ""

local numbers "& (1) & (2) & (3) & (4) \\"
local fs1 "\textbf{A: Main Effect} & \multicolumn{1}{c}{Schooling}   &  \multicolumn{1}{c}{Primary}  &  \multicolumn{1}{c}{Primary} &  \multicolumn{1}{c}{Secondary} \\ "
local fs2 "\midrule \\ \textbf{B: Democracy Threatened} & \multicolumn{1}{c}{Schooling}   &  \multicolumn{1}{c}{Primary}  &  \multicolumn{1}{c}{Primary} &  \multicolumn{1}{c}{Secondary} \\"
local line2 " & & \multicolumn{1}{c}{incomplete} & \multicolumn{1}{c}{complete}  & \multicolumn{1}{c}{incomplete} \\  \midrule"
local fstat " First-stage \textit{F} statistic & `fstat_school4'	 & `fstat_indiv2' & `fstat_indiv3' & `fstat_indiv4' \\"
local fstat2 " First-stage \textit{F} statistic & `fstat2_school4'	 & `fstat2_indiv2' & `fstat2_indiv3' & `fstat2_indiv4'  & `fstat2_secondary_school' \\"

esttab est1 est3 est5 est7 using "tables/first_stage.tex", replace b(3) se(3) ar(3) ///
stats(N, fmt(0 3 3 "") labels(`"Observations"')) nonumber ///
posthead("`numbers'" "`fs1'" "`line2'") postfoot("`fstat'") ///
f label nomtitles nogaps booktabs noobs compress star(* 0.10 ** 0.05 *** 0.01) keep(instrument)

esttab est2 est4 est6 est8 using "tables/first_stage.tex", append b(3) se(3) ar(3) ///
stats(N, fmt(0 3 3 "") labels(`"Observations"')) nonumber ///
posthead("`gap'" "`fs2'" "`line2'") postfoot("`fstat2'") ///
f label nomtitles nogaps booktabs noobs compress star(* 0.10 ** 0.05 *** 0.01) keep(instrument c.instrument#c.W)



********************************************************************************
***   Main effects
********************************************************************************

*********************************
***   Economic and Interest   ***
*********************************

est clear

local economic economic_index employed assets basic_necessities 


label var economic_index "Econ index"
label var basic_necessities "Basic necessities"
label var employed "Employed"
label var assets "Assets index"


foreach var of varlist `economic' {
	
	display " "
	display " "
	display " "
	display "Table A16a: `var'"
	
	quietly eststo: ivreg2 `var' (school4 = instrument) $controls i.locale_gender if birthyear_control >= 1970 & birthyear_control <= 1997, cluster(locale_3_control) partial(i.birthyear_control i.year_survey_control i.locale_gender) savefirst savefprefix(post1)

	noisily: lincom school4
	quietly summ `var' if e(sample)
	estadd scalar vmean = r(mean)
	
	weakiv
	local ar_ts_`var' = round(e(ar_chi2), 0.001)
	local arp_`var' = round(e(ar_p), 0.001)
	local ar_cl_`var' = e(ar_cset)

}

ren interest_pub_affairs_index int_pub_affairs_index
local information information int_pub_affairs_index discuss_pol_index news_scale

foreach var of varlist `information' {
	
	display " "
	display " "
	display " "
	display "Table A16b: `var'"
	
	quietly eststo: ivreg2 `var' (school4 = instrument) $controls i.locale_gender if birthyear_control >= 1970 & birthyear_control <= 1997, cluster(locale_3_control) partial(i.birthyear_control i.year_survey_control i.locale_gender) savefirst savefprefix(post1)

	noisily: lincom school4
	quietly summ `var' if e(sample)
	estadd scalar vmean = r(mean)
	
	weakiv
	local ar_ts_`var' = round(e(ar_chi2), 0.001)
	local arp_`var' = round(e(ar_p), 0.001)
	local ar_cl_`var' = e(ar_cset)
	
}

ren int_pub_affairs_index interest_pub_affairs_index 


local numbers "& (1) & (2) & (3) & (4) \\"
local economic "\textbf{A: Economic} & \multicolumn{1}{c}{Economic index} &  \multicolumn{1}{c}{Employed}  &  \multicolumn{1}{c}{Assets index}  &  \multicolumn{1}{c}{Basic necessities index} \\  \midrule"
local interest "\midrule \\ \textbf{B: Interest} & \multicolumn{1}{c}{Interest index} &  \multicolumn{1}{c}{Interest in pub affairs}  &  \multicolumn{1}{c}{Discuss politics}  &  \multicolumn{1}{c}{News index} \\  \midrule"

local ar_ts1 " AR t-stat & `ar_ts_economic_index' & `ar_ts_employed' & `ar_ts_assets' & `ar_ts_basic_necessities' \\"
local arp1 " AR p-value & `arp_economic_index' & `arp_employed' & `arp_assets' & `arp_basic_necessities' \\"
local ar_cl1 " AR CIs & `ar_cl_economic_index' & `ar_cl_employed' & `ar_cl_assets' & `ar_cl_basic_necessities' \\"

local ar_ts2 " AR t-stat & `ar_ts_information' & `ar_ts_int_pub_affairs_index' & `ar_ts_discuss_pol_index' & `ar_ts_news_scale' \\"
local arp2 " AR p-value & `arp_information' & `arp_int_pub_affairs_index' & `arp_discuss_pol_index' & `arp_news_scale' \\ "
local ar_cl2 " AR CIs & `ar_cl_information' & `ar_cl_int_pub_affairs_index' & `ar_cl_discuss_pol_index' & `ar_cl_news_scale' \\"

local gap ""

esttab est1 est2 est3 est4 using "tables/iv_econ_interest.tex", replace b(3) se(3) ar(3) ///
stats(N vmean, fmt(0 3 3 "") labels(`"Observations"' `"DV Mean"')) nonumber ///
posthead("`numbers'" "`economic'")  postfoot("`ar_ts1'" "`arp1'" "`ar_cl1'")  ///
f label nomtitles nogaps booktabs noobs compress star(* 0.10 ** 0.05 *** 0.01) keep(school4)

esttab est5 est6 est7 est8 using "tables/iv_econ_interest.tex", b(3) se(3) ar(3) ///
stats(N vmean, fmt(0 3 3 "") labels(`"Observations"' `"DV Mean"')) ///
nonumber posthead("`gap'" "`interest'") postfoot("`ar_ts2'" "`arp2'" "`ar_cl2'") append ///
f label nomtitles nogaps booktabs noobs compress star(* 0.10 ** 0.05 *** 0.01) keep(school4)


*************************
***   PARTICIPATION   ***
*************************


local participation participation_index participate_index contact_index 
est clear

foreach var of varlist `participation' {
	
	display " "
	display " "
	display " "
	display "Table A17a: `var'"
	
	quietly eststo: ivreg2 `var' (school4 = instrument) $controls i.locale_gender if birthyear_control >= 1970 & birthyear_control <= 1997, cluster(locale_3_control) partial(i.birthyear_control i.year_survey_control i.locale_gender) savefirst savefprefix(post1)

	noisily: lincom school4
	quietly summ `var' if e(sample)
	estadd scalar vmean = r(mean)

	
	weakiv
	local ar_ts1_`var' = round(e(ar_chi2), 0.001)
	local arp1_`var' = round(e(ar_p), 0.001)
	local ar_cl1_`var' = e(ar_cset)
	
}


foreach var of varlist `participation' {
	
	display " "
	display " "
	display " "
	display "Table A17b: `var'"
	
	quietly eststo: ivreg2 `var' (school4 c.school4#c.W = instrument c.instrument#c.W) i.birthyear_control##c.W i.locale_gender##c.W c.post1##c.W c.treat2_10_inc##c.W $controls2 if birthyear_control >= 1970 & birthyear_control <= 1997, cluster(locale_3_control) partial(i.birthyear_control##c.W i.locale_gender##c.W c.post1##c.W c.treat2_10_inc##c.W) savefirst savefprefix(post1)

	noisily: lincom school4
	noisily: lincom c.school4#c.W
	quietly summ `var' if e(sample)
	estadd scalar vmean = r(mean)
	
	weakiv, strong(school4)
	local ar_ts2_`var' = round(e(ar_chi2), 0.001)
	local arp2_`var' = round(e(ar_p), 0.001)
	local ar_cl2_`var' = e(ar_cset)
}	



local numbers "& (1) & (2) & (3) \\ "
local participation1 "\textbf{A: Main Effects} & \multicolumn{1}{c}{Participation index} &  \multicolumn{1}{c}{Participate index}&  \multicolumn{1}{c}{Contact index} \\ \midrule"
local participation2 "\midrule \\ \textbf{B: Democracy Threatened} & \multicolumn{1}{c}{Participation index} &  \multicolumn{1}{c}{Participate index}&  \multicolumn{1}{c}{Contact index} \\ \midrule"
local gap ""

local ar_ts1 "AR t-stat & `ar_ts1_participation_index' & `ar_ts1_participate_index' & `ar_ts1_contact_index' \\ "
local arp1 " AR p-value& `arp1_participation_index' & `arp1_participate_index' & `arp1_contact_index' \\"
local ar_cl1 " AR CIs & `ar_cl1_participation_index' & `ar_cl1_participate_index' & `ar_cl1_contact_index' \\"

local ar_ts2 " AR t-stat & `ar_ts2_participation_index' & `ar_ts2_participate_index' & `ar_ts2_contact_index' \\"
local arp2 " AR p-value& `arp2_participation_index' & `arp2_participate_index' & `arp2_contact_index' \\"
local ar_cl2 "AR CIs & `ar_cl2_participation_index' & `ar_cl2_participate_index' & `ar_cl2_contact_index' \\ \bottomrule"


esttab est1 est2 est3 using "tables/iv_participation.tex", replace b(3) se(3) ar(3) ///
stats(N vmean, fmt(0 3 3 "") labels(`"Observations"' `"DV Mean"')) nonumber ///
posthead("`numbers'" "`participation1'")  postfoot("`ar_ts1'" "`arp1'" "`ar_cl1'") ///
f label nomtitles nogaps booktabs noobs compress star(* 0.10 ** 0.05 *** 0.01) keep(school4)

esttab est4 est5 est6 using "tables/iv_participation.tex", append b(3) se(3) ar(3) ///
stats(N vmean, fmt(0 3 3 "") labels(`"Observations"' `"DV Mean"')) ///
nonumber posthead("`gap'" "`participation2'")  postfoot("`ar_ts2'" "`arp2'" "`ar_cl2'") ///
f label nomtitles nogaps booktabs noobs compress star(* 0.10 ** 0.05 *** 0.01) keep(school4 c.school4#c.W)




************************************
***   Government and Democracy   ***
************************************

local democracy dem_gov dem_support dem_checks_on_pres dem_institutions
est clear

foreach var of varlist `democracy' {
	
	display " "
	display " "
	display " "
	display "Table A18a: `var'"
	
	quietly eststo: ivreg2 `var' (school4 = instrument) $controls i.locale_gender if birthyear_control >= 1970 & birthyear_control <= 1997, cluster(locale_3_control) partial(i.birthyear_control i.year_survey_control i.locale_gender) savefirst savefprefix(post1)

	noisily: lincom school4
	quietly summ `var' if e(sample)
	estadd scalar vmean = r(mean)

	
	weakiv
	local ar_ts1_`var' = round(e(ar_chi2), 0.001)
	local arp1_`var' = round(e(ar_p), 0.001)
	local ar_cl1_`var' = e(ar_cset)
	
}


foreach var of varlist `democracy' {
	
	display " "
	display " "
	display " "
	display "Table A18b: `var'"
	
	quietly eststo: ivreg2 `var' (school4 c.school4#c.W = instrument c.instrument#c.W) i.birthyear_control##c.W i.locale_gender##c.W c.post1##c.W c.treat2_10_inc##c.W $controls2 if birthyear_control >= 1970 & birthyear_control <= 1997, cluster(locale_3_control) partial(i.birthyear_control##c.W i.locale_gender##c.W c.post1##c.W c.treat2_10_inc##c.W) savefirst savefprefix(post1)

	noisily: lincom school4
	noisily: lincom c.school4#c.W
	quietly summ `var' if e(sample)
	estadd scalar vmean = r(mean)
	
	weakiv, strong(school4)
	local ar_ts2_`var' = round(e(ar_chi2), 0.001)
	local arp2_`var' = round(e(ar_p), 0.001)
	local ar_cl2_`var' = e(ar_cset)
}	



local numbers "& (1) & (2) & (3) & (4) \\ "
local dem1 "\textbf{A: Support for Democracy} & \multicolumn{1}{c}{Democratic} &  \multicolumn{1}{c}{Dem support}&  \multicolumn{1}{c}{Checks on} &  \multicolumn{1}{c}{Dem institutions} \\"
local dem2 "\midrule \\ \textbf{B: Democracy Threatened} & \multicolumn{1}{c}{Democratic} &  \multicolumn{1}{c}{Dem support}&  \multicolumn{1}{c}{Checks on} &  \multicolumn{1}{c}{Dem institutions} \\"
local line2 "& \multicolumn{1}{c}{quality index} &  \multicolumn{1}{c}{index}&  \multicolumn{1}{c}{president} &  \multicolumn{1}{c}{index} \\ \midrule"
local gap ""

local ar_ts1 " AR t-stat& `ar_ts1_dem_gov' & `ar_ts1_dem_support' & `ar_ts1_dem_checks_on_pres'  & `ar_ts1_dem_institutions' \\"
local arp1 " AR p-value& `arp1_dem_gov' & `arp1_dem_support' & `arp1_dem_checks_on_pres'  & `arp1_dem_institutions' \\"
local ar_cl1 "AR CIs & `ar_cl1_dem_gov' & `ar_cl1_dem_support' & `ar_cl1_dem_checks_on_pres'  & `ar_cl1_dem_institutions' \\"

local ar_ts2 " AR t-stat& `ar_ts2_dem_gov' & `ar_ts2_dem_support' & `ar_ts2_dem_checks_on_pres'  & `ar_ts2_dem_institutions' \\"
local arp2 " AR p-value & `arp2_dem_gov' & `arp2_dem_support' & `arp2_dem_checks_on_pres' & `arp2_dem_institutions' \\"
local ar_cl2 "AR CIs & `ar_cl2_dem_gov' & `ar_cl2_dem_support' & `ar_cl2_dem_checks_on_pres'  & `ar_cl2_dem_institutions' \\"


esttab est1 est2 est3 est4 using "tables/iv_democracy.tex", replace b(3) se(3) ar(3) ///
stats(N vmean, fmt(0 3 3 "") labels(`"Observations"' `"DV Mean"')) nonumber ///
posthead("`numbers'" "`dem1'"  "`line2'") postfoot("`ar_ts1'" "`arp1'" "`ar_cl1'")  ///
f label nomtitles nogaps booktabs noobs compress star(* 0.10 ** 0.05 *** 0.01) keep(school4)

esttab est5 est6 est7 est8 using "tables/iv_democracy.tex", b(3) se(3) ar(3) ///
stats(N vmean, fmt(0 3 3 "") labels(`"Observations"' `"DV Mean"')) ///
nonumber posthead("`gap'" "`dem2'"  "`line2'") postfoot("`ar_ts2'" "`arp2'" "`ar_cl2'") append ///
f label nomtitles nogaps booktabs noobs compress star(* 0.10 ** 0.05 *** 0.01) keep(school4 c.school4#c.W)

